﻿/*
 * My Timer - frmShutDown.cs
 * 
 * Copyright (C) 2009 Ahmad Hanis Azmi
 * 
 * This file is part of My Timer
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace My_Timer
{
    public partial class frmShutDown : Form
    {
        private byte ShutDownCode = 0;
        private int CountDown = 30;

        public frmShutDown()
        {
            InitializeComponent();
        }

        private void timerShutDown_Tick(object sender, EventArgs e)
        {
            CountDown--;

            setLabelString();

            if (CountDown <= 0)
            {
                timerShutDown.Enabled = false;
                Shutdown.Shutdown.f_Shutdown(ShutDownCode.ToString());
                Close();
                Dispose();
            }
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            timerShutDown.Enabled = false;
            Shutdown.Shutdown.f_Shutdown(ShutDownCode.ToString());
            Close();
            Dispose();
        }

        private void frmShutDown_Load(object sender, EventArgs e)
        {
            CountDown = 30;
            ShutDownCode = (byte)this.Tag;

            AcceptButton = buttonOK;
            CancelButton = buttonCancel;

            setLabelString();
            timerShutDown.Enabled = true;
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            timerShutDown.Enabled = false;
            Close();
            Dispose();
        }

        private void setLabelString()
        {
            string s = "";

            if (CountDown <= 1)
            {
                s = " second.";
            }
            else
            {
                s = " seconds.";
            }

            switch (ShutDownCode)
            {
                case 1:
                    labelShutDown.Text = "Your computer will shutdown in " + CountDown.ToString() + s;
                    buttonOK.Text = "Shutdown (" + CountDown.ToString() + ")";

                    break;

                case 2:
                    labelShutDown.Text = "Your computer will restart in " + CountDown.ToString() + s;
                    buttonOK.Text = "Restart (" + CountDown.ToString() + ")";

                    break;
            }
        }
    }
}
